#include <stdio.h>
#include <stdlib.h>
/*int compare(int a[], int size,int remaining){
    int count=0;
    for (int i=0; i<size;i++){
        int num=a[i];
        if (num==remaining){
            count++;
            continue;
        }
        if (num>remaining){continue;}
        if (i==size-1){break;}
        else{
            int *b=a+(i+1);
            int count2=compare(b,size-i-1,remaining-num);
            count+=count2;
        }
    }
    return count; 
}*/
int *a=NULL;


int compare(int n, int remaining) {
    int b[remaining+1][n + 1];
    for(int i=0;i<=remaining;i++){
		for(int j=0;j<=n;j++){
			b[i][j]=0;
		}
	}

    for (int i = 0; i <=remaining; i++) {
        
        for (int j = 0; j <=n;j++) {
            

            if (i == 0) {
                b[i][j]=1; //前j块组成体积i的方法
            }else if (j==0){
                b[i][j]=0; // 没有时，不能组成体积i
            }else{
                if (a[j-1]<=i) {
                    b[i][j]+=b[i][j-1];
                    b[i][j]+=b[i-a[j-1]][j-1];
                }else{
                    b[i][j]+=b[i][j-1];
                }
            }
        }

    }
    /*for (int i=0; i<=remaining; i++) {
        for (int j=0; j<=n; j++) {
            printf("%d ",b[i][j]);
        }
        printf("\n");
    }
    printf("1");*/
    return b[remaining][n];
}




void main(){
    int time=0;
    int n;
    int num=0;
    
    while(scanf("%d",&n)!=EOF){
        if (time==0){num=n;a=(int *)malloc(num*sizeof(int));}
        else{
            a[time-1]=n;
        }
        if (time==num){
            time=0;
            int count=compare(num,40);
            printf("%d",count);
            printf("\n");
            free(a);
            continue;
        }

        time+=1;
    }


}